import { defineConfig } from 'eslint/config';
import globals from 'globals';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import pluginReactRefresh from 'eslint-plugin-react-refresh';
import pluginReact from 'eslint-plugin-react';
import pluginPrettier from 'eslint-plugin-prettier';
import pluginImport from 'eslint-plugin-import';
import stylisticPlugin from '@stylistic/eslint-plugin';

import tseslint from 'typescript-eslint';
import configPrettier from 'eslint-config-prettier';
import { getESLintConfig } from '@hdtd/coding-style';

export default defineConfig(
  { ignores: ['dist'] },
  {
    extends: [
      getESLintConfig({
        import: pluginImport,
        '@stylistic': stylisticPlugin,
        ts: tseslint,
        react: pluginReact
      }),
      configPrettier
    ],
    files: ['**/*.{js,jsx,ts,tsx}'],
    settings: {
      react: {
        version: 'detect'
      }
    },
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser
    },
    plugins: {
      'react-hooks': pluginReactHooks,
      'react-refresh': pluginReactRefresh,
      prettier: pluginPrettier
    },
    rules: {
      ...pluginReactHooks.configs.recommended.rules,
      'react-refresh/only-export-components': ['error', { allowConstantExport: true }],
      'prettier/prettier': 'error',
      'react-hooks/exhaustive-deps': 'off',
      'react/self-closing-comp': 'off'
    }
  }
);
